# web应用程序:http协议
import socket

sock = socket.socket()
sock.bind(('127.0.0.1', 8080))
sock.listen(5)
while True:
    conn, addr = sock.accept()
    data = conn.recv(1024)
    print("客户端发送的消息:", data)
    # 游览器无法解析
    # conn.send(b"hello world")
    # 响应头
    # conn.send(b"HTTP/1.0 200 OK\r\nserver:zheng\r\n\r\nhello world")
    # 响应头
    # content-type:text/html 页面 content-type:application.json json字符串
    conn.send(b"HTTP/1.0 200 OK\r\nserver:zheng\r\ncontent-type:text/html\r\n\r\n<h1>hello world</h1>")
    conn.close()
